﻿@*
    生成者：未登录用户
    生成时间：2021/5/31 10:49:32
    代码由代码生成器自动生成，更改的代码可能被进行替换
    界面如需更改，建议直接将内容剪切到自己的文件内，保留此空白文件
    菜单列表
*@
@using Caviar.Models
@namespace Caviar.AntDesignPages.Pages.Menu
@inherits DataComponentBase<ViewMenu>
@page "/Menu/Add"
@page "/Menu/Update"
<Form @ref="_meunForm" Model="@DataSource" OnFinish="FormSubmit">
    <FormItem Label='菜单名称'>
        <Input @bind-Value="@context.MenuName" Style="width:50%" />
    </FormItem>
    <FormItem Label="上层目录">
        <Dropdown>
            <Overlay>
                <Tree ShowIcon DataSource="SysMenus"
                      TitleExpression="x => x.DataItem.MenuName"
                      ChildrenExpression="x => x.DataItem.Children"
                      IconExpression="x => x.DataItem.Icon"
                      IsLeafExpression="x => x.DataItem.Children?.Count == 0"
                      KeyExpression="x => x.DataItem.Id.ToString()"
                      OnClick='e=>EventRecord(e)'
                      TItem="ViewMenu">
                </Tree>
            </Overlay>
            <ChildContent>
                <Button OnClick="RemoveRecord">@ParentMenuName</Button>
            </ChildContent>
        </Dropdown>
    </FormItem>
    <FormItem Label="菜单类型">
        <CavEnum TData="MenuType" @bind-Value="@context.MenuType"
                 OnChange="EventCallback.Factory.Create<MenuType>(this, CheckMenuType)"></CavEnum>
    </FormItem>
    <FormItem Label="按钮位置" Style="@buttonStrle">
        <CavEnum TData="ButtonPosition" @bind-Value="@context.ButtonPosition"></CavEnum>
    </FormItem>
    <FormItem Label="请求地址" Style="@visibility">
        <Input @bind-Value="@context.Url">
    </FormItem>
    <FormItem Label="打开方式" Style="@visibility">
        <CavEnum TData="TargetType" @bind-Value="@context.TargetType"></CavEnum>
    </FormItem>
    <FormItem Style="@buttonStrle">
        <Checkbox @bind-Value="@context.IsDoubleTrue">需要二次确认</Checkbox>
    </FormItem>
    <FormItem Label="图标">
        <Space>
            <SpaceItem>
                <Button OnClick="()=> { _visible = true; }">图标库</Button>
                <CavModalIcon @bind-IconValue="DataSource.Icon" @bind-Visible="_visible"></CavModalIcon>
            </SpaceItem>
            <SpaceItem>
                @if (!string.IsNullOrEmpty(DataSource.Icon))
                {
                    <Icon Type="@DataSource.Icon" Theme="outline"></Icon>
                }
            </SpaceItem>
        </Space>
    </FormItem>
    <FormItem Label="编号">
        <Input @bind-Value="@context.Number" Style="width: 20%;">
    </FormItem>
    <FormItem Label='数据权限'>
        <CavUserGroup DataSource='ViewUserGroups'
                      UserGroupName='@UserGroupName'
                      OnSelect='OnUserGroupSelect'
                      OnCancel='OnUserGroupCancel'>
        </CavUserGroup>
    </FormItem>
</Form>

@code{

    bool _visible = false;

    string visibility = "display:none;";
    string buttonStrle = "display:none;";
    public void CheckMenuType()
    {
        switch (DataSource.MenuType)
        {
            case MenuType.Catalog:
                visibility = "display:none;";
                buttonStrle = "display:none;";
                DataSource.Url = "";
                DataSource.ButtonPosition = ButtonPosition.Default;
                DataSource.TargetType = TargetType.CurrentPage;
                break;
            case MenuType.Menu:
            case MenuType.API:
                buttonStrle = "display:none;";
                visibility = "";
                DataSource.ButtonPosition = ButtonPosition.Default;
                DataSource.TargetType = TargetType.CurrentPage;
                break;
            case MenuType.Button:
                visibility = "";
                buttonStrle = "";
                break;
            default:
                break;
        }
    }


}